﻿// LightNet - Lightweight .NET Framework
// Copyright (c) 2010 http://lightnet.codeplex.com

namespace System
{
    /// <summary>
    /// Specifies the usage of another attribute class. This class cannot be inherited.
    /// </summary>
    [AttributeUsage(AttributeTargets.Class, Inherited = true)]
    public sealed class AttributeUsageAttribute : Attribute
    {
        internal static AttributeUsageAttribute Default = new AttributeUsageAttribute(AttributeTargets.All);

        /// <summary>
        /// Gets or sets a Boolean value indicating whether more than one instance of the indicated attribute can be specified for a single program element.
        /// </summary>
        /// <returns>true if more than one instance is allowed to be specified; otherwise, false. The default is false.</returns>
        public bool AllowMultiple { get; set; }

        /// <summary>
        /// Gets or sets a Boolean value indicating whether the indicated attribute can be inherited by derived classes and overriding members.
        /// </summary>
        /// <returns>true if the attribute can be inherited by derived classes and overriding members; otherwise, false. The default is true.</returns>
        public bool Inherited { get; set; }

        /// <summary>
        /// Gets a set of values identifying which program elements that the indicated attribute can be applied to.
        /// </summary>
        /// <returns>One or several <see cref="T:System.AttributeTargets" /> values. The default is All.</returns>
        public AttributeTargets ValidOn  { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.AttributeUsageAttribute" /> class with the specified list of <see cref="T:System.AttributeTargets" />, the <see cref="P:System.AttributeUsageAttribute.AllowMultiple" /> value, and the <see cref="P:System.AttributeUsageAttribute.Inherited" /> value.
        /// </summary>
        /// <param name="validOn">The set of values combined using a bitwise OR operation to indicate which program elements are valid.</param>
        public AttributeUsageAttribute(AttributeTargets validOn)
        {
            ValidOn = AttributeTargets.All;
            Inherited = true;
            ValidOn = validOn;
        }

        internal AttributeUsageAttribute(AttributeTargets validOn, bool allowMultiple, bool inherited)
        {
            ValidOn = AttributeTargets.All;
            Inherited = true;
            ValidOn = validOn;
            AllowMultiple = allowMultiple;
            Inherited = inherited;
        }
    }
}
